package com.arqui.admmon_module.server.handlers;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.rpc.ServiceException;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.arqui.admmon_module.client.action.HistoricServices;
import com.arqui.admmon_module.client.action.HistoricServicesResult;
import com.arqui.admmon_module.server.services.ExternalEventsService;
import com.arqui.admmon_module.server.webservices.eventsmonitor.NonexistentEntityException;
import com.arqui.admmon_module.server.webservices.eventsmonitor.UnknownHostException;
import com.arqui.admmon_module.shared.ServicesEntity;
import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.shared.ActionException;

public class HistoricServicesActionHandler implements
		ActionHandler<HistoricServices, HistoricServicesResult> {

	@Inject
	public HistoricServicesActionHandler() {
	}

	@Override
	public HistoricServicesResult execute(HistoricServices action,
			ExecutionContext context) throws ActionException {
		ExternalEventsService service = new ExternalEventsService();
		List<ServicesEntity> result= new ArrayList<ServicesEntity>();
		try {
			result = service.getExternaServicesHistoric(action.getStartDate(), action.getEndDate());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (NonexistentEntityException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
;		return new HistoricServicesResult(result);
	}

	@Override
	public void undo(HistoricServices action, HistoricServicesResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<HistoricServices> getActionType() {
		return HistoricServices.class;
	}
}
